package huy.mmt.gamelathinh.components;

import huy.mmt.gamelathinh.Play;
import android.os.CountDownTimer;
import android.view.View;

public class MyCountDownTimer extends CountDownTimer {

	
	public long startTrunggian;
	boolean blink;
	long totalTimeCountInMilliseconds;
	

	public MyCountDownTimer(long totalTimeCountInMilliseconds, long interval) {
		super(totalTimeCountInMilliseconds, interval);
	}

	@Override
	public void onFinish() {
		// bao het thoi gian
		Play.textViewShowTime.setText("Time up!!");
		Play.mPlay.showdialogGameOver();
	}

	@Override
	public void onTick(long leftTimeInMilliseconds) {
		long seconds = leftTimeInMilliseconds / 1000;

		ReadTime(leftTimeInMilliseconds);

		Play.startTrunggian = Long.valueOf(leftTimeInMilliseconds);
		Play.textViewShowTime.setText(String.format("%02d", seconds / 60) + ":"
				+ String.format("%02d", seconds % 60));
		// format the textview to show the easily readable format
	}
	public void ReadTime(long leftTimeInMilliseconds) {
		if (leftTimeInMilliseconds < 10 * 1000) {
			if (blink) {
				Play.textViewShowTime.setVisibility(View.VISIBLE);
				// if blink is true, textview will be visible
			} else {
				Play.textViewShowTime.setVisibility(View.INVISIBLE);
			}
			blink = !blink;
		}

	}

}
